#ifndef DEVICEHELPER_H
#define DEVICEHELPER_H

#include <QDateTime>
#include <QObject>
#include <QTimer>

#include "IDevice.h"
#include "ModbusManager.h"

class DeviceHelper : public IDevice
{
public:
    DeviceHelper(QString deviceName, QObject* parent = nullptr);
    ~DeviceHelper();
    // Modbus操作方法
    void setDeviceTime(const QDateTime& datetime) override;
    void control(quint16 optCode) override;

    bool saveDeviceConfig(const QVariantMap& configMap) override;
signals:

private slots:
    void onGetDeviceData() override;
    void onGetDeviceData2(ModbusHelper* modbus);

private:
    void checkAndRecordCalibration();
    void checkAndRecordInspection();
    void loadDeviceConfig();
    void checkMeasurementRange(float value);  // 检测测量值是否在范围内

    // 存储上次的时间，用于检测变化
    QDateTime m_lastCalib1Time;
    QDateTime m_lastCalib2Time;
    QDateTime m_lastInspectionTime;

    // 数据读取计数器，每个实例独立
    quint32 m_dataCount = 0;
};

#endif  // !DEVICE_MANAGER_H
